﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace AwesomeGame
{
    public class DestructableWorldItem
    {
        public int Health { get; set; }
        public Vector2 Position { get; set; }
        public bool isDestroyed { get; set; }
        public Vector2 TilePosition { get; set; }

        private Texture2D _sprite;
        private Texture2D _destroyedSprite;

        public DestructableWorldItem(Vector2 tilePosition, Vector2 position, int health)
        {
            TilePosition = tilePosition;
            Health = health;
            Position = position;
            _sprite = Game1.ContentManager.Load<Texture2D>(@"Terrain\Crate");
            _destroyedSprite = Game1.ContentManager.Load<Texture2D>(@"Terrain\Crate-Destroyed");
        }

        public void Draw(GameTime gameTime)
        {
            Vector2 screenPosition = Camera.GetScreenPosition(Position);
            if(isDestroyed)
                Game1.SpriteBatch.Draw(_destroyedSprite, screenPosition, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
            else
                Game1.SpriteBatch.Draw(_sprite, screenPosition, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.8f);
        }

        public void Update(GameTime gameTime)
        {
            if (isDestroyed == false && Health <= 0)
            {
                isDestroyed = true;
            }
        }

        public Rectangle GetCollisionRectangle()
        {
            return new Rectangle((int)Position.X, (int)Position.Y, _sprite.Width, _sprite.Height);
        }
    }
}
